﻿@using Masa.Blazor.Presets

<div class="text-center">
    <PMobileDateTimePicker @bind-Value="_dateTime" Formatter="@CustomFormatter">
        <ActivatorContent>
            <MButton Color="primary" Class="text-capitalize" Text @attributes="@context.Attrs">
                @(_dateTime == default ? "Please select" : _dateTime)
            </MButton>
        </ActivatorContent>
    </PMobileDateTimePicker>
</div>

@code {

    private DateTime _dateTime;

    private static string CustomFormatter(DateTimePrecision type, int val)
    {
        return type switch 
        {
            DateTimePrecision.Year => $"{val}年",
            DateTimePrecision.Month => $"{val}月",
            DateTimePrecision.Day => $"{val}日",
            DateTimePrecision.Hour => $"{val}时",
            DateTimePrecision.Minute => $"{val}分",
            DateTimePrecision.Second => $"{val}秒",
            _ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
        };
    }

}
